package com.hyundaihds.hdscontacts;

import android.app.Activity;
import android.content.*;
import android.content.res.*;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;

public class Menu1 extends Activity {
	/** Called when the activity is first created. */
	Spinner s1;
	Spinner s2;
	Spinner s3;

	String setitem1;
	String setitem2;
	String setitem3;

	ArrayAdapter adapter1;

	ArrayAdapter adapter10;
	ArrayAdapter adapter11;
	ArrayAdapter adapter12;

	ArrayAdapter adapter111;
	ArrayAdapter adapter112;
	ArrayAdapter adapter113;
	ArrayAdapter adapter114;
	ArrayAdapter adapter115;
	ArrayAdapter adapter116;
	ArrayAdapter adapter117;
	ArrayAdapter adapter118;

	ArrayAdapter adapter2;
	ArrayAdapter adapter3;
	ArrayAdapter adapter4;
	
	String code = "GI";
	
	
	String cd = "";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu1);

		// 대분류 - 기술실, 본부 별 Spinner 셋팅
		s1 = (Spinner) findViewById(R.id.spinner1);
		adapter1 = ArrayAdapter.createFromResource(this, R.array.hq,
				android.R.layout.simple_spinner_item);
		adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		s1.setAdapter(adapter1);

		s1.setOnItemSelectedListener(m);


		
		
		// 중분류 - 센터별 Spinner 셋팅
		s2 = (Spinner) findViewById(R.id.spinner2);
		adapter11 = ArrayAdapter.createFromResource(this, R.array.centers,
				android.R.layout.simple_spinner_item);
		adapter11
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		s2.setAdapter(adapter2);
		s2.setSelection(7);
		s2.setOnItemSelectedListener(m2);

		// 소분류 - 팀별 Spinner 셋팅
		s3 = (Spinner) findViewById(R.id.spinner3);
		adapter111 = ArrayAdapter.createFromResource(this, R.array.teams1,
				android.R.layout.simple_spinner_item);

		adapter112 = ArrayAdapter.createFromResource(this, R.array.teams2,
				android.R.layout.simple_spinner_item);
		adapter113 = ArrayAdapter.createFromResource(this, R.array.teams3,
				android.R.layout.simple_spinner_item);
		adapter114 = ArrayAdapter.createFromResource(this, R.array.teams4,
				android.R.layout.simple_spinner_item);
		adapter115 = ArrayAdapter.createFromResource(this, R.array.teams5,
				android.R.layout.simple_spinner_item);
		adapter116 = ArrayAdapter.createFromResource(this, R.array.teams6,
				android.R.layout.simple_spinner_item);
		adapter117 = ArrayAdapter.createFromResource(this, R.array.teams7,
				android.R.layout.simple_spinner_item);
		adapter118 = ArrayAdapter.createFromResource(this, R.array.teams8,
				android.R.layout.simple_spinner_item);
		adapter111
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		adapter112
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		adapter113
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		adapter114
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		adapter115
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		adapter116
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		adapter117
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		adapter118
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

		s3.setAdapter(adapter111);
		s1.setSelection(2);

		Button b = (Button) findViewById(R.id.Bt1);
		b.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub

				Intent intent = new Intent(Menu1.this, List1.class);
				
				cd = (String)s3.getSelectedItem();
				
				if(cd.equals("없음"))
				{
					cd = (String)s2.getSelectedItem();
					
					if(cd.equals("없음"))
					{
						cd = (String)s1.getSelectedItem();
					}
					
					
				}
				
				
				
				onListItemClick(v);

				intent.putExtra("team_nm", cd);	//층 정보

				startActivity(intent);
			}
		});

	}
	
	
	

	protected void onListItemClick(View v) {
		Toast.makeText(this, cd, Toast.LENGTH_SHORT).show();
	}
	
	
	
	

	private OnItemSelectedListener m2 = new OnItemSelectedListener() {

		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			setitem2 = (String) s2.getSelectedItem();

			// 이제 Spinner1 클릭시 값에 따라 Spinner2에 보여질 항목들을 셋팅한다.

			if (setitem2.equals("개발지원센터")) {
				s3.setAdapter(adapter111);

			} else if (setitem2.equals("경영서비스센터")) {
				s3.setAdapter(adapter112);

			} else if (setitem2.equals("기술지원센터")) {
				s3.setAdapter(adapter113);

			} else if (setitem2.equals("서비스지원센터")) {
				s3.setAdapter(adapter114);

			} else if (setitem2.equals("시스템지원센터")) {
				s3.setAdapter(adapter115);

			} else if (setitem2.equals("업무서비스1센터")) {
				s3.setAdapter(adapter116);

			} else if (setitem2.equals("업무서비스2센터")) {
				
				s3.setAdapter(adapter117);

			} else {
				s3.setAdapter(adapter118);
			}

		}

		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}

	};

	private OnItemSelectedListener m = new OnItemSelectedListener() {

		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			setitem1 = (String) s1.getSelectedItem();

			if (setitem1.equals("정보기술실")) {
				s2.setAdapter(adapter11);

			} else {
				s2.setAdapter(adapter11);
			}

		}

		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}

	};

}